package controllers

import (
	"cute0517/models"
	beego "github.com/beego/beego/v2/server/web"
)

type TypesController struct {
	beego.Controller
}

func (c *TypesController) TypesAdd() {
	name := c.GetString("name")
	types := models.Types{
		Name: name,
	}

	if err := models.DB.Create(&types).Error; err != nil {
		c.Data["json"] = Res{
			Code:    500,
			Data:    nil,
			Message: "添加失败",
		}
		c.ServeJSON()
		return
	}
	c.Data["json"] = Res{
		Code:    200,
		Data:    types,
		Message: "添加成功",
	}
	c.ServeJSON()
	return
}
